#include "DXWindow.h"
#include "DX.h"
#include "FourPointsPrimitive.h"

DXWindow::DXWindow( const WNDCLASSEX& wndClass, MRect rect, std::wstring title ) : Window( wndClass, rect, title )
{
	init_();
}

DXWindow::DXWindow( MRect rect, std::wstring title ) : Window( rect, title )
{
	init_();
}

DXWindow::~DXWindow( )
{
	delete DX::_();
}

void DXWindow::update( )
{
	DX::_()->device->BeginScene();
	DX::_()->device->Clear( 0, 0, D3DCLEAR_TARGET, 0, 1.0f, 0 );

	Window::update();

	DX::_()->device->EndScene();
	DX::_()->device->Present( NULL, NULL, NULL, NULL );
}

void DXWindow::init_()
{
#if defined( FULLSCREEN )
	DX::_()->init( hWnd(), false );
#else
	DX::_()->init( hWnd() );
#endif
	
	D3DXMATRIX tm;
	
	DX::_()->device->SetTransform( D3DTS_WORLD, D3DXMatrixIdentity( &tm ) );
	DX::_()->device->SetTransform( D3DTS_PROJECTION, &tm );
	
	D3DXMATRIX matView;

	D3DXVECTOR3 vecVP, vecTP, vecUp( 0.0f, -1.0f, 0.0f );
	vecVP.x = 0;
	vecVP.y = 0;
	vecVP.z = 1;
	vecTP.x = vecTP.y = vecTP.z = 0.0f;
	D3DXMatrixLookAtLH( &matView, &vecVP, &vecTP, &vecUp );

	DX::_()->device->SetTransform( D3DTS_VIEW, &matView );
}